package com.example.campusforumapi.service.impl;

import com.example.campusforumapi.dao.CommentMapper;
import com.example.campusforumapi.dao.UserMapper;
import com.example.campusforumapi.entity.Comment;
import com.example.campusforumapi.entity.User;
import com.example.campusforumapi.service.CommentService;
import com.example.campusforumapi.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public PageResult getCommentPage(Integer page, Integer pageSize, Integer userId, String commentType, Integer commentId, Integer targetId, String content) {
        //1.设置分页参数
        PageHelper.startPage(page,pageSize);
//        2.执行查询
        List<Comment> commentList = commentMapper.list(userId,commentType,commentId,targetId,content);
        Page<Comment> p = (Page<Comment>) commentList;
//        3.封装PageResult对象
        PageResult pageResult = new PageResult(p.getResult(),p.getTotal(),p.getPageSize(),p.getPageNum());
        return pageResult;
    }

    @Override
    public int delComment(List<Integer> ids) {
        return commentMapper.delComment(ids);
    }

    @Override
    public int updComment(Comment comment) {
        return commentMapper.updComment(comment);
    }
}
